﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using RoadTeam.Pub;
using RoadTeam.BLL;
using RoadTeam.Standard;
using System.Data;

public partial class 对接测试页面_验房项目 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        #region 生成插入数据

        List<CsHomeInspection_Temp> Temp = new List<CsHomeInspection_Temp>();
        //String Identifier = String.Empty;
        CsHomeInspection_Temp HomeInspection_Temp = new CsHomeInspection_Temp();
        CsValidateRoom ValidateRoom = new CsValidateRoom();
        //Identifier = CreateIdentifier.GetIdentifier();
        ValidateRoom.ValidateRoomIdentifier = String.Empty;
        ValidateRoom.ValidateRoomCode = @"100860001"; ;
        ValidateRoom.FoundDate = DateTime.Now;
        ValidateRoom.ValidateStaffIdentifier = @"91f53a607ad84fbea774a0fc4a55b699";
        ValidateRoom.DeveloperOpinion = @"很好,很不错的说";
        ValidateRoom.SubjoinExplain = @"很好,很不错的说";
        ValidateRoom.ValidateRoomState = @"已完成";
        ValidateRoom.UnitIdentifier = @"03e776126ab14f7c9db3b704aecef946";
        ValidateRoom.OrganIdentifier = @"2ccb50e091784ba5b2a66e4bb2727dab";
        HomeInspection_Temp.ValidateRoom = ValidateRoom;

        List<CsValidateRoomInfo> li = new List<CsValidateRoomInfo>();
        CsValidateRoomInfo info = new CsValidateRoomInfo();
        info.ValidateRInfoIdentifier = String.Empty;
        info.ValidateRoomIdentifier = String.Empty;
        info.RoomTypeIdentifier = @"36dd5f14c7204507a1c419bbafe26a03";
        info.ValidateObjectIdentifier = @"f8bdf1ebff8e47fa8218ec8c13ffbf21";
        info.ValidateProIdentifier =@"e6fc31014ad34ec4b5d23e5904a15eaf";
        info.ValidateState = @"有缺陷";
        info.ValidateExplain = @"有缺陷是正常的";
        info.IsRepair = false;
        info.FillStaffIdentifier = @"91f53a607ad84fbea774a0fc4a55b699";
        info.FillDate = DateTime.Now;
        info.RepairBeginDate = DateTime.Now;
        info.RepairEndDate = DateTime.Now;
        li.Add(info);

        info = new CsValidateRoomInfo();
        info.ValidateRInfoIdentifier = String.Empty;
        info.ValidateRoomIdentifier = String.Empty ;
        info.RoomTypeIdentifier = @"36dd5f14c7204507a1c419bbafe26a03";
        info.ValidateObjectIdentifier = @"f8bdf1ebff8e47fa8218ec8c13ffbf21";
        info.ValidateProIdentifier = @"f4c4b1ead6844de98ce9d16d87705f95";
        info.ValidateState = @"有缺陷";
        info.ValidateExplain = @"有缺陷是正常的";
        info.IsRepair = false;
        info.FillStaffIdentifier = @"91f53a607ad84fbea774a0fc4a55b699";
        info.FillDate = DateTime.Now;
        info.RepairBeginDate = DateTime.Now;
        info.RepairEndDate = DateTime.Now;
        li.Add(info);
        HomeInspection_Temp.ValidateRoomInfo = li.ToArray();
        Temp.Add(HomeInspection_Temp);

        #region 备份原来的代码
 //List<CsHomeInspection_Temp> Temp = new List<CsHomeInspection_Temp>();
        //String Identifier = String.Empty;
        //CsHomeInspection_Temp HomeInspection_Temp = new CsHomeInspection_Temp();
        //CsValidateRoom ValidateRoom = new CsValidateRoom();
        //Identifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.ValidateRoomIdentifier = Identifier;
        //ValidateRoom.ValidateRoomCode = @"100860001"; ;
        //ValidateRoom.FoundDate = DateTime.Now;
        //ValidateRoom.ValidateStaffIdentifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.DeveloperOpinion = @"很好,很不错的说";
        //ValidateRoom.SubjoinExplain = @"很好,很不错的说";
        //ValidateRoom.ValidateRoomState = @"已完成";
        //ValidateRoom.UnitIdentifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.OrganIdentifier = CreateIdentifier.GetIdentifier();
        //HomeInspection_Temp.ValidateRoom = ValidateRoom;

        //List<CsValidateRoomInfo> li = new List<CsValidateRoomInfo>();
        //CsValidateRoomInfo info = new CsValidateRoomInfo();
        //info.ValidateRInfoIdentifier = Identifier;
        //info.ValidateRoomIdentifier = CreateIdentifier.GetIdentifier();
        //info.RoomTypeIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateObjectIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateProIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateState = @"有缺陷";
        //info.ValidateExplain = @"有缺陷是正常的";
        //info.IsRepair = false;
        //info.FillStaffIdentifier = CreateIdentifier.GetIdentifier();
        //info.FillDate = DateTime.Now;
        //info.RepairBeginDate = DateTime.Now;
        //info.RepairEndDate = DateTime.Now;
        //li.Add(info);

        //info = new CsValidateRoomInfo();
        //info.ValidateRInfoIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateRoomIdentifier = Identifier;
        //info.RoomTypeIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateObjectIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateProIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateState = @"有缺陷";
        //info.ValidateExplain = @"有缺陷是正常的";
        //info.IsRepair = false;
        //info.FillStaffIdentifier = CreateIdentifier.GetIdentifier();
        //info.FillDate = DateTime.Now;
        //info.RepairBeginDate = DateTime.Now;
        //info.RepairEndDate = DateTime.Now;
        //li.Add(info);
        //HomeInspection_Temp.ValidateRoomInfo = li.ToArray();
        //Temp.Add(HomeInspection_Temp);
        #endregion
        #region 注释掉的代码
        //HomeInspection_Temp = new CsHomeInspection_Temp();
        //ValidateRoom = new CsValidateRoom();
        //Identifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.ValidateRoomIdentifier = Identifier;
        //ValidateRoom.ValidateRoomCode = @"100860002"; ;
        //ValidateRoom.FoundDate = DateTime.Now;
        //ValidateRoom.ValidateStaffIdentifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.DeveloperOpinion = @"很好,很不错的说";
        //ValidateRoom.SubjoinExplain = @"很好,很不错的说";
        //ValidateRoom.ValidateRoomState = @"未完成";
        //ValidateRoom.UnitIdentifier = CreateIdentifier.GetIdentifier();
        //ValidateRoom.OrganIdentifier = CreateIdentifier.GetIdentifier();
        //HomeInspection_Temp.ValidateRoom = ValidateRoom;

        //li = new List<CsValidateRoomInfo>();
        //info = new CsValidateRoomInfo();
        //info.ValidateRInfoIdentifier = Identifier;
        //info.ValidateRoomIdentifier = CreateIdentifier.GetIdentifier();
        //info.RoomTypeIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateObjectIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateProIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateState = @"无缺陷";
        //info.ValidateExplain = @"无缺陷";
        //info.IsRepair = false;
        //info.FillStaffIdentifier = CreateIdentifier.GetIdentifier();
        //info.FillDate = DateTime.Now;
        //info.RepairBeginDate = DateTime.Now;
        //info.RepairEndDate = DateTime.Now;
        //li.Add(info);

        //info = new CsValidateRoomInfo();
        //info.ValidateRInfoIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateRoomIdentifier = Identifier;
        //info.RoomTypeIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateObjectIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateProIdentifier = CreateIdentifier.GetIdentifier();
        //info.ValidateState = @"无缺陷";
        //info.ValidateExplain = @"无缺陷是正常的";
        //info.IsRepair = false;
        //info.FillStaffIdentifier = CreateIdentifier.GetIdentifier();
        //info.FillDate = DateTime.Now;
        //info.RepairBeginDate = DateTime.Now;
        //info.RepairEndDate = DateTime.Now;
        //li.Add(info);
       // HomeInspection_Temp.ValidateRoomInfo = li.ToArray();
        //Temp.Add(HomeInspection_Temp);

        #endregion

        CsHomeInspection Inspection = new CsHomeInspection();
        Inspection.Item = Temp.ToArray();


        JavaScriptSerializer jvs = new JavaScriptSerializer();
        TextBox1.Text = RoadTeam.Pub.ConverJson.ConverJsonDateTime(jvs.Serialize(Inspection));

        #endregion
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        String Json = TextBox1.Text;


        CsHomeInspection Inspection = new CsHomeInspection();

        JavaScriptSerializer jvs = new JavaScriptSerializer();

        Inspection = jvs.Deserialize<CsHomeInspection>(Json);



        DataTable dt_ValidateRoom = CsValidateRoomBll.GetEmptyTable();
        DataRow dr_ValidateRoom;
        DataTable dt_ValidateRoomInfo = CsValidateRoomInfoBLL.GetEmptyTable();
        DataRow dr_ValidateRoomInfo;

        String ValidateRoomIdentifier = String.Empty;
        #region 解析成两个DataTable
        foreach (CsHomeInspection_Temp Temp in Inspection.Item)
        {

            dr_ValidateRoom = dt_ValidateRoom.NewRow();
            ValidateRoomIdentifier = CreateIdentifier.GetIdentifier();
            dr_ValidateRoom["ValidateRoomIdentifier"] = ValidateRoomIdentifier;
            dr_ValidateRoom["ValidateRoomCode"] = Temp.ValidateRoom.ValidateRoomCode;
            dr_ValidateRoom["FoundDate"] = Temp.ValidateRoom.FoundDate;
            dr_ValidateRoom["ValidateStaffIdentifier"] = Temp.ValidateRoom.ValidateStaffIdentifier;
            dr_ValidateRoom["DeveloperOpinion"] = Temp.ValidateRoom.DeveloperOpinion;
            dr_ValidateRoom["SubjoinExplain"] = Temp.ValidateRoom.SubjoinExplain;
            dr_ValidateRoom["ValidateRoomState"] = Temp.ValidateRoom.ValidateRoomState;
            dr_ValidateRoom["UnitIdentifier"] = Temp.ValidateRoom.UnitIdentifier;
            dr_ValidateRoom["OrganIdentifier"] = Temp.ValidateRoom.OrganIdentifier;
            Temp.ValidateRoom.ValidateRoomIdentifier = ValidateRoomIdentifier;
            foreach (CsValidateRoomInfo info in Temp.ValidateRoomInfo)
            {

                dr_ValidateRoomInfo = dt_ValidateRoomInfo.NewRow();
                dr_ValidateRoomInfo["ValidateRInfoIdentifier"] = CreateIdentifier.GetIdentifier();
                dr_ValidateRoomInfo["ValidateRoomIdentifier"] = ValidateRoomIdentifier;
                dr_ValidateRoomInfo["RoomTypeIdentifier"] = info.RoomTypeIdentifier;
                dr_ValidateRoomInfo["ValidateObjectIdentifier"] = info.ValidateObjectIdentifier;
                dr_ValidateRoomInfo["ValidateProIdentifier"] = info.ValidateProIdentifier;
                dr_ValidateRoomInfo["ValidateState"] = info.ValidateState;
                dr_ValidateRoomInfo["ValidateExplain"] = info.ValidateExplain;
                dr_ValidateRoomInfo["IsRepair"] = info.IsRepair;
                dr_ValidateRoomInfo["FillStaffIdentifier"] = info.FillStaffIdentifier;
                dr_ValidateRoomInfo["FillDate"] = info.FillDate;
                dr_ValidateRoomInfo["RepairBeginDate"] = info.RepairBeginDate;
                dr_ValidateRoomInfo["RepairEndDate"] = info.RepairEndDate;
                info.ValidateRInfoIdentifier = dr_ValidateRoomInfo["ValidateRInfoIdentifier"].ToString();
                dt_ValidateRoomInfo.Rows.Add(dr_ValidateRoomInfo);
            }
            dt_ValidateRoom.Rows.Add(dr_ValidateRoom);
        }
        #endregion

        BllBase blbase = new BllBase();
        blbase.InserLog(Json);

        CsValidateRoomBll roombll = new CsValidateRoomBll();
        roombll.insert(dt_ValidateRoom);

        CsValidateRoomInfoBLL infobll = new CsValidateRoomInfoBLL();
        infobll.insert(dt_ValidateRoomInfo);
        //return Inspection;
    }
}